define(['app'], function(app) {
	'use strict';

	//实例化方法
	var factory = function(Http) {
		function get_data_group_detail(result) {
			if(HTTP_ISLOGIC) {
				result = '{"success":true,"msg":"","result":{"act_id":"001","name":"团购","start_time":"2017/01/01 09:00:00","end_time":"2017/02/01 09:00:00","create_group":true,"has_packets":true,"video_type":"1","image":[{"id":"001","image":"img/upload/pro-img01.jpg"},{"id":"002","image":"img/upload/pro-img01.jpg"}],"brand_id":"001","brand_name":"方法","cat_type":[{"id":"001","name":"手动工具"},{"id":"002","name":"电动工具"}]},"session":"7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else
				return result;
		};

		function get_data_group_dealer(result) {
			if(HTTP_ISLOGIC) {
				result = '{"success":true,"msg":"","result":{"region":[{"region_id":"001","region_name":"江苏","is_all":false,"store":[{"store_id":"001","store_name":"世达"},{"store_id":"002","store_name":"博士"}]},{"region_id":"002","region_name":"浙江","is_all":true,"store":[{"store_id":"003","store_name":"益达"},{"store_id":"004","store_name":"飞达"}]}],"goods":[{"goods_id":"001","goods_name":"一字螺丝刀","image":"001.jpg","price":10.5,"deposit":10,"groupbuy_rule":[{"id":"001","group_count":5,"days":1,"promotion_price":9.5},{"id":"002","group_count":8,"days":1,"promotion_price":8}],"least_buy_num":10,"mail_free":true,"count":1000},{"goods_id":"002","goods_name":"十字螺丝刀","image":"001.jpg","price":10.5,"deposit":10,"groupbuy_rule":[{"id":"001","promotion_price":7,"days":1,"group_count":15},{"id":"002","promotion_price":8,"days":1,"group_count":20}],"least_buy_num":10,"mail_free":false,"count":1000}],"change_price":true},"session":"7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else
				return result;
		};
		function get_data_group_agenterjion(result){
			if(HTTP_ISLOGIC){
				result = '{"success": true,"msg": "","result": {"act_id": "001"},"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			}else
			return result;
		}
		//返回信息
		return {
			//获取首页数据
			group_detail: function(act_id, callback) {
				//post请求
				Http.post({
					method: 'marketing.groupbuy.detail',
					act_id: act_id,
					picSize: 'CS'
				}, function(result) {
					//函数回调
					if(callback)
						callback(get_data_group_detail(result).result);
				}, function(e) {

				}, function() {

				});

			},
			group_dealer: function(act_id, callback) {
				
				Http.post({
					method: 'marketing.groupbuy.dealer',
					act_id: act_id
				}, function(result) {
					if(callback)
					callback(get_data_group_dealer(result).result);
				}, function(e) {

				}, function() {

				})
			},
			group_agenterjion:function(act_id,region,goods,mail_free,callback){
				var updateParams = new Object();
				updateParams.act_id = act_id;
				updateParams.order_flg = order_flg;
				updateParams.advance = advance;
				updateParams.rule = rule;
				updateParams = JSON.stringify(updateParams);
				Http.post({
					method:'marketing.groupbuy.agenterjion',
					updateParams:updateParams
				},function(result){
					if(callback)
					callback(get_data_group_agenterjion(result));
				},function(e){
					
				},function(){
					
				})
			},
		};
	}

	factory.$inject = ['Http'];
	return app.registerService("favoritectrl", factory);
});